package org.wenhuayuan.project.main.demo;

import android.os.Bundle;
import android.widget.Toast;

import androidx.annotation.NonNull;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;

import org.wenhuayuan.project.common.uicomp.HiBaseActivity;
import org.wenhuayuan.project.main.R;
import org.wenhuayuan.uilibrary.tab.common.IHiTabLayout;
import org.wenhuayuan.uilibrary.tab.top.HiTabTopInfo;
import org.wenhuayuan.uilibrary.tab.top.HiTabTopLayout;

import java.util.ArrayList;
import java.util.List;
@Route(path = "/demo/title/activity")
public class DemoActivity extends HiBaseActivity {
    final String[] tabsStr = new String[]{
            "热门",
            "服装",
            "数码",
            "鞋子",
            "零食",
            "家电",
            "汽车",
            "百货",
            "家居",
            "装修",
            "运动"
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_demo);
        ARouter.getInstance().inject(this);
        initTabTop();
    }
    private void initTabTop() {
        HiTabTopLayout tabTopLayout = findViewById(R.id.hi_tab_top_layout);
        List<HiTabTopInfo<?>> listInfo = new ArrayList<>();
        int defaultColor = getResources().getColor(R.color.tabBottomDefaultColor);
        int selectedColor = getResources().getColor(R.color.tabBottomTintColor);
        for (String name : tabsStr) {
            HiTabTopInfo<Integer> info = new HiTabTopInfo<>(name, defaultColor, selectedColor);
            listInfo.add(info);
        }
        tabTopLayout.inflateInfo(listInfo);
        tabTopLayout.addTabSelectedChangeListener(new IHiTabLayout.OnTabSelectedListener<HiTabTopInfo<?>>() {
            @Override
            public void onTabSelectedChange(int index, HiTabTopInfo<?> prevInfo, @NonNull HiTabTopInfo<?> nextInfo) {
                Toast.makeText(DemoActivity.this, nextInfo.name, Toast.LENGTH_SHORT).show();
            }
        });
        tabTopLayout.defaultSelected(listInfo.get(0));
    }
}
